/**
 * @param {string} s
 * @return {string[]}
 */
var letterCasePermutation = function(s) {
  let res = [], tempArr = [];

  function alphaToArr(alpha) {
    return [alpha.toLowerCase(), alpha.toUpperCase()];
  }

  function dfs(depth) {
    // console.log(tempArr);
    if(depth == s.length) {
      res.push(tempArr.join(''));
      return ;
    }
    if(s[depth] >= '0' && s[depth] <= '9') {
      tempArr.push(s[depth]);
      dfs(depth + 1);
      tempArr.splice(tempArr.length - 1, 1);
    } else {
      const arr = alphaToArr(s[depth]);
      for(let i = 0; i < arr.length; i++) {
        tempArr.push(arr[i]);
        dfs(depth + 1);
        tempArr.splice(tempArr.length - 1, 1);
      }
    }

  }

  dfs(0);
  return res;

};
let s = "a1b2";
console.log(letterCasePermutation(s));
s = "3z4";
console.log(letterCasePermutation(s));

